import {screen}  from "electron"
import Win from '../win.coffee'
import destroy from '../destroy.coffee'

{camera} = Win

win = undefined
position = undefined

CIRCLE = 204

init_w = init_h = CIRCLE

export x = =>
  if win and not win.isDestroyed()
    if win.getSize()[0] != 800
      position = win.getPosition()
  destroy win
  return

export size = (s)=>
  init_w = init_h = s
  pre = win.getSize()[0]
  if pre == s
    return
  position = win.getPosition()
  diff = Math.round (s-pre)/2
  win.setBounds(
    x:position[0]-diff
    y:position[1]-diff
    width:s
    height:s
  )
  return


TOP = false

export rect = =>
  摄像头 800,500

export default 摄像头 = (width,height)=>
  if win and not win.isDestroyed()
    return
  init_w = width
  init_h = height

  win = camera {
    width
    height
    center: true
    roundedCorners: false
    resizable: false
    transparent:true
    #minWidth:80
    #minHeight:50
  }
  if TOP
    top()
  return


export circle = (w)=>
  if win and not win.isDestroyed()
    return
  w = w or CIRCLE
  #if select_area != undefined
  #  position = undefined

  #AREA = select_area - 0

  摄像头 w,w

  if position
    [_x,_y] = position
  else
    {width,height} = screen.getPrimaryDisplay().size
    padding = 62
    _x = padding
    _y = height-padding-w
  win.setPosition _x,_y
  return

export x_rect = =>
  x()
  rect()
  return

export top = =>
  if win and not win.isDestroyed()
    win.setAlwaysOnTop(true,'pop-up-menu')
    win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
  TOP = true
  return

export untop = =>
  if win and not win.isDestroyed()
    win.setAlwaysOnTop(false)
    win.setVisibleOnAllWorkspaces(false)
  TOP = false
  return
